/**
 * Created by oneminute on 8/4/14.
 */

var lz = require("../lib/utils/modules")();

exports.post = function (_req, _res, _opts, _callback) {
    if (!_opts.user) {
        lz.Logger.warn("/modifypassword: 临时用户。");
        _callback(lz.Config.errors.getError(lz.Config.errors.REQUEST_TEMPUSER_ERROR));
        return;
    }

    var user = _opts.user;
    var oldPassword = lz.Utils.decrypt(_opts.oldpassword);
    var newPassword = lz.Utils.decrypt(_opts.newpassword);
    user.modifyPassword(oldPassword, newPassword, function (_err, _user) {
        if (_err) {
            lz.Logger.error("/modifypassword: 修改密码错误。");
            _callback(_err, user);
            return;
        }

        lz.Logger.debug("/modifypassword: 修改密码成功。");
        _callback(null, user);
    });
};
